//
//  PYMineNormalCell.m
//  IHome
//
//  Created by zhujizheng on 2020/2/15.
//  Copyright © 2019年 com.zhujizheng. All rights reserved.
//

#import "PYMineNormalCell.h"

@interface PYMineNormalCell ()
/// 图标
@property (nonatomic, strong) UIImageView *iconImgView;
/// 标题
@property (nonatomic, strong) UILabel *titleLabel;
/// 红点
@property (nonatomic, strong) UIView *redPointView;
@end

@implementation PYMineNormalCell

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    PYMineNormalCell *cell = [tableView dequeueReusableCellWithIdentifier:@"normalCellid"];
    if (!cell) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"normalCellid"];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    [cell initIconImgView];
    [cell initTitleLabel];
    [cell setLightSelectedBackgroundColor];
    return cell;
}

#pragma mark - iconImgView
- (UIImageView *)iconImgView
{
    if (!_iconImgView) {
        _iconImgView = [UIImageView new];
    }
    return _iconImgView;
}

- (void)initIconImgView
{
    [self.contentView addSubview:self.iconImgView];
    [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(17);
        make.centerY.mas_equalTo(self);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
}

- (void)setIcon:(UIImage *)icon
{
    _icon = icon;
    self.iconImgView.image = icon;
}

#pragma mark - titleLabel
- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.textColor = PY_Dark_Color;
        _titleLabel.font = PY_Font_Regular(17);
    }
    return _titleLabel;
}

- (void)initTitleLabel
{
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(55);
        make.centerY.mas_equalTo(0);
        make.height.mas_equalTo(self);
        make.width.mas_equalTo(0);
    }];
}

- (void)setTitle:(NSString *)title
{
    _title = [title copy];
    if (_title) {
        self.titleLabel.text = _title;
        CGSize size = [self.titleLabel.text sizeWithFont:self.titleLabel.font];
        [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(size.width);
        }];
        if ([title isEqualToString:@"心情"]) {
            [self.iconImgView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.size.mas_equalTo(CGSizeMake(23, 23));
                make.left.mas_equalTo(15.5);
            }];
        } else if ([title isEqualToString:@"发现"]) {
            [self.iconImgView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.size.mas_equalTo(CGSizeMake(16, 16));
                make.left.mas_equalTo(19);
            }];
        } else {
            [self.iconImgView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.size.mas_equalTo(CGSizeMake(20, 20));
                make.left.mas_equalTo(17);
            }];
        }
    } else {
        self.titleLabel.text = @"";
    }
}

#pragma mark - redPointView
- (UIView *)redPointView
{
    if (!_redPointView) {
        _redPointView = [UIView new];
        _redPointView.layer.cornerRadius = 5;
        _redPointView.layer.masksToBounds = YES;
        _redPointView.layer.borderColor = [UIColor colorWithRed:253.f/255.f green:69.f/255.f blue:75.f/255.f alpha:1].CGColor;
        _redPointView.layer.borderWidth = 5;
        _redPointView.hidden = YES;
    }
    return _redPointView;
}

- (void)initRedPointView
{
    [self.contentView addSubview:self.redPointView];
    [self.redPointView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.titleLabel.mas_right).mas_offset(8);
        make.centerY.mas_equalTo(self);
        make.size.mas_equalTo(CGSizeMake(10, 10));
    }];
}

@end
